<?php
/**
 * @author Wei Ma
 * @copyright 2014 pipahr.com
 */
JLoader::register("PReportsModelReports", OC::$SERVERROOT."/apps/reports/lib/reports.php");
JLoader::register("PReportsHelper", OC::$SERVERROOT."/apps/reports/lib/helper.php");
JLoader::register("PCompanyModelCompany", OC::$SERVERROOT."/apps/company/lib/company.php");
JLoader::register("PJobpositionHelper", OC::$SERVERROOT.'/apps/jobposition/lib/helper.php');
JLoader::register('ProvinceHelper', JPATH_SITE.'/components/com_city/helper.php');

class PReportsController
{
   // Home page view
   public static function home() {
      if(!PUtil::checkUserLogin(true))
         return;

      $nav = new OCP\Template('reports', 'part.reports.nav', '');
      $nav->assign('item', 'summary');

      $model = new PReportsModelReports();
      $tmpl = new OCP\Template('reports', 'home', 'user');
      $tmpl->assign('page_title', '统计管理-综合统计');
      $tmpl->assign('nav', $nav->fetchPage());
      $tmpl->assign('stats', $model->getTotalStats());
      $tmpl->printPage();
   }

   public static function position() {
      if(!PUtil::checkUserLogin(true))
         return;

      $nav = new OCP\Template('reports', 'part.reports.nav', '');
      $nav->assign('item', 'position');

      $model = new PReportsModelReports();
      $tmpl = new OCP\Template('reports', 'position', 'user');
      $tmpl->assign('page_title', '统计管理-职位统计');
      $tmpl->assign('nav', $nav->fetchPage());
      $tmpl->assign('stats', $model->getTotalStats());
      $tmpl->printPage();
   }

   public static function positiondetail() {
      if(!PUtil::checkUserLogin(true))
         return;

      $nav = new OCP\Template('reports', 'part.reports.nav', '');
      $nav->assign('item', 'positiondetail');

      $model = new PReportsModelReports();
      $job_title = $model->getJobTitle();
      if (empty($job_title))
         jexit('职位不存在或已被删除');

      $tmpl = new OCP\Template('reports', 'positiondetail', 'user');
      $tmpl->assign('page_title', '统计管理-职位统计详情');
      $tmpl->assign('nav', $nav->fetchPage());
      $tmpl->assign('job_title', $job_title);
      $tmpl->printPage();
   }

   public static function subaccount() {
      if(!PUtil::checkUserLogin(true))
         return;

      $nav = new OCP\Template('reports', 'part.reports.nav', '');
      $nav->assign('item', 'subaccount');

      $tmpl = new OCP\Template('reports', 'subaccount', 'user');
      $tmpl->assign('page_title', '统计管理-子账号统计');
      $tmpl->assign('nav', $nav->fetchPage());
      $tmpl->printPage();
   }

   public static function subaccountdetail() {
      if(!PUtil::checkUserLogin(true))
         return;

      $nav = new OCP\Template('reports', 'part.reports.nav', '');
      $nav->assign('item', 'subaccountdetail');
      
      $model = new PReportsModelReports();
      $subaccountName = $model->getSubaccountName();
      if (empty($subaccountName))
         jexit('子账号不存在或已被删除');
      
      $tmpl = new OCP\Template('reports', 'subaccountdetail', 'user');
      $tmpl->assign('page_title', '统计管理-子账号统计详情');
      $tmpl->assign('nav', $nav->fetchPage());
      $tmpl->assign('subaccountName', $subaccountName);
      $tmpl->printPage();
   }

   public static function contrast() {
      if(!PUtil::checkUserLogin(true))
         return;

      $nav = new OCP\Template('reports', 'part.reports.nav', '');
      $nav->assign('item', 'contrast');

      $tmpl = new OCP\Template('reports', 'contrast', 'user');
      $tmpl->assign('page_title', '统计管理-对比统计');
      $tmpl->assign('nav', $nav->fetchPage());
      $tmpl->printPage();
   }

}
